package com.zhiyun.yycall;

import java.io.File;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Environment;

import com.gzit.utils.AndroidUtils;
import com.gzit.utils.Base64;
import com.gzit.utils.MD5;
import com.gzit.utils.StringUtils;
import com.zhiyun.common.DESUtils;
import com.zhiyun.common.YYCallUtils;

public class Config {

	public static final String ACTION_CALL = "com.zhiyun.callbackuu.action.CALL";
	public static final String ACTION_CALLHISTORY = "com.zhiyun.callbackuu.action.CALLHISTORY";

	public static final String APP_DIR = Environment
			.getExternalStorageDirectory().getAbsolutePath()
			+ File.separator
			+ "yunzhihu" + File.separator;

	private static String password;
	private static String phoneNo;

	public static void load() {
		SharedPreferences sp = getSharedPreferences();
		password = sp.getString("password", "");
		phoneNo = sp.getString("phoneNo", "");

		if (!StringUtils.isBlank(password)) {
			password = YYCallUtils.encryptPwd(phoneNo, password);
		}

	}

	// 获得未加密的密码
	public static String getPlainPassword() {
		SharedPreferences sp = getSharedPreferences();
		return sp.getString("password", "");

	}

	public static void setPassword(String password) {
		Editor editor = prepare();
		editor.putString("password", password);
		editor.commit();

		// 密码的加密处理
		Config.password = YYCallUtils.encryptPwd(phoneNo, password);
	}

	public static void setPhoneNo(String phoneNo) {

		Editor editor = prepare();
		editor.putString("phoneNo", phoneNo);
		editor.commit();
		Config.phoneNo = phoneNo;

	}

	public static String getPassword() {
		if (StringUtils.isBlank(password)) {
			return password;
		}
		return password;
	}

	public static String getPhoneNo() {
		return phoneNo;
	}

	public static Editor prepare() {
		return getSharedPreferences().edit();

	}

	public static SharedPreferences getSharedPreferences() {
		return AndroidUtils.appCtx().getSharedPreferences("Config",
				Context.MODE_PRIVATE);

	}

}
